<?php

namespace app\user\model;

use Carbon\Carbon;
use think\Exception;
use think\Log;
use think\Lang;
use app\common\model\Orders as commonOrders;
use app\common\Token;
class Orders extends commonOrders
{

	/**
     * 根据订单信息获取房车信息
     * @return [type] [description]
     */
    public function caravan()
    {
        return $this->belongsTo('Caravans','caravan_id');
    }

    /**
     * 根据订单信息获取营地信息
     * @return [type] [description]
     */
    public function camp()
    {
        return $this->belongsTo('Camps','camp_id');
    }

	public function payOrder($querys = [], $use_travel_coin = null, $use_blance = null, $others = [])
	{
		$order_info = parent::payOrder($querys, $use_travel_coin, $use_blance, $others);//halt($order_info);
		if (!$order_info->paid_at) {
			$param  = [
                'order_id' => urlencode($order_info->number),
                'pt'       => urlencode('wx_pay'),
                'body'     => urlencode(Lang::get('RV Reservation Order')),
                'detail'   => urlencode($order_info->toJson()), 
                'total'    => urlencode($order_info->difference * 100)
            ];

            $sign  = Token::createToken($param);
            $param = array_merge($param, ['sign' => $sign]);
            return $param;
		}
        return true;
	}

}
